package qj.util.collection;

import java.util.HashMap;
import java.util.Map;

import qj.util.funct.F0;

public class ExtendableMap<K, V> extends HashMap<K, V> implements Map<K, V> {
	private final F0<V> funct;
	public ExtendableMap(F0<V> funct) {
		this.funct = funct;
	}

	@SuppressWarnings("unchecked")
	public V get(Object key) {
		V result = super.get(key);
		if (result == null) {
			result = funct.e();
			put((K) key, result);
		}
		
		return result;
	}
	
	
}
